package com.qianfeng.shoon.pet;

import android.app.Application;
import android.widget.Toast;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.qianfeng.shoon.pet.netstate.NetChangeObserver;
import com.qianfeng.shoon.pet.netstate.NetWorkUtil;
import com.qianfeng.shoon.pet.netstate.NetworkStateReceiver;
import com.qianfeng.shoon.pet.utils.ImageLoaderUtils;


/**
 * Created by Shoon on 2015/10/9.
 */
public class BaseApp extends Application{
    private static BaseApp app;
    public static BaseApp getInstance() {
        return app;
    }


    private NetChangeObserver observer = new NetChangeObserver() {
        @Override
        public void onConnect(NetWorkUtil.NetType type) {
            super.onConnect(type);
            switch (type) {
                case WIFI:
                    showToast("亲!WIFI已连接");
                    break;
                default:
                    showToast("亲!网络已连接");
                    break;
            }
        }

        @Override
        public void onDisConnect() {
            super.onDisConnect();
            showToast("网络未连接,请打开网络!!!");
        }
    };


    /**
     * 初始化网络监听
     */
    private void initNetState() {
        NetworkStateReceiver.registerNetworkStateReceiver(this);
        NetworkStateReceiver.registerObserver(observer);
    }


    public void unegisterNetworkStateReceiver() {
        NetworkStateReceiver.removeRegisterObserver(observer);
        NetworkStateReceiver.unRegisterNetworkStateReceiver(this);
    }

    public void showToast(String msg) {
        Toast.makeText(BaseApp.this, msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        initNetState();
        //配置图片加载框架
        ImageLoaderUtils.configGolbalImageLoader(this);
        Fresco.initialize(this);
       // ImageLoaderUtils.getOptions();
     //   Fresco.initialize(this, FrescoHelper.getImagePipelineConfig(this));

    }


}
